import uniqueId from "@form-create/utils/lib/unique";
import {
  localeProps,
  makeOptionsRule,
  makeRequiredRule,
} from "../../utils/index";

const label = "树形控件";
const name = "tree";

export default {
  icon: "icon-tree",
  label,
  name,
  rule({ t }) {
    const opt = t("props.option");
    return {
      type: "a-tree-select",
      field: uniqueId(),
      title: t("components.tree.name"),
      info: "",
      effect: {
        fetch: "",
      },
      $required: false,
      props: {
        fieldNames: {
          title: "label",
          key: "value",
        },
        showCheckbox: true,
        data: [1, 2].map((value) => {
          return {
            label: opt + value,
            value: value,
            children: [],
          };
        }),
      },
    };
  },
  props(_, { t }) {
    return localeProps(t, name + ".props", [
      makeRequiredRule(),
      makeOptionsRule(t, "props.data", false),
      {
        type: "input",
        field: "placeholder",
        title: "输入框提示文字",
      },
      {
        type: "switch",
        field: "allowSearch",
        title: "是否可搜索",
      },
      {
        type: "switch",
        field: "allowClear",
        title: "是否可以清空选项",
      },
      {
        type: "switch",
        field: "treeCheckable",
        title: "是否展示复选框",
      },
      {
        type: "switch",
        field: "multiple",
        title: "是否支持多选",
      },
      {
        type: "inputNumber",
        field: "maxTagCount",
        title: "多选情况下，最多显示的标签数量",
      },
      {
        type: "switch",
        field: "treeCheckStrictly",
        title: "父子节点是否关联",
      },
    ]);
  },
};
